// pages/electronic/electronic.js
const app = getApp();
import {
  OrdersModel
} from "../../utils/models/orders/Orders-models";
var ordersModel = new OrdersModel;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navbarHeight: app.globalData.navbarHeight,
    isHeight: true,
    navBgColor: 'yellow',
    titleName: '电子凭证',
    isLeft: true,
    business:{},
    order:{},
    description: '<img src="/images/test/shuoming1.png" style="width:100%">',
  },

  // 自助核销
  goWriteOff: function() {
    var that = this;
    wx.navigateTo({
      url: './write_off?id='+that.data.order.id,
    })
  },

  // 拨打手机号码
  phoneCall: function (e) {
    var tel = this.data.business.phone;
    if (tel) {
      wx.makePhoneCall({
        phoneNumber: tel,
        success: function (res) {

        },
        fail: function (res) {
          console.log('拨打失败')
        }
      })
    }

  },

  // 打开地图查看地址
  onLocation: function () {
    var that = this;
    wx.getLocation({
      type: 'gcj02', //返回可以用于wx.openLocation的经纬度
      success(res) {
        const latitude = parseFloat(that.data.business.latitude);
        const longitude = parseFloat(that.data.business.longitude);

        wx.openLocation({
          latitude,
          longitude,
          scale: 18,
          name: that.data.business.title,
          address: that.data.business.address
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    if(!id){
      id = options.scene;
    }
    var param = {
      'oid':id
    }
    var that = this;
    ordersModel.voucher(param,function(res){
      console.log(res);
      that.setData({  
        business:res.data.business,
        order:res.data.order
      })
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})